// ValidationAspects
// Written by Mike Saunders
// Released under Microsoft Public License (Ms-PL)
using System;
using ValidationAspects.Core;

namespace ValidationAspects.Sdk
{
	public class Validator<T> : IValidator<T>
	{
		private readonly Action<T, IValidationContext> _validateAction;

		public Validator(Action<T, IValidationContext> validateAction)
		{
			Enforce.IsNotNull(validateAction, "validateAction");
			_validateAction = validateAction;
		}

		#region Implementation of IValidator
		public void Invoke(T value, IValidationContext context)
		{
			_validateAction(value, context);
		}

		public void Invoke(object value, IValidationContext context)
		{
			_validateAction(Cast<T>.From(value), context);
		}
		#endregion
	}
}